//
//  BaseNavigationController.m
//  FintechAdvisor
//
//  Created by mac on 2017/5/11.
//  Copyright © 2017年 菲鹿. All rights reserved.
//

#import "BaseNavigationController.h"

@interface BaseNavigationController ()

@end

@implementation BaseNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationBar.backgroundColor = [UIColor clearColor];
    self.navigationBar.barTintColor = [UIColor clearColor];
    UIImage *newImage = [UIImage imageNamed:@"nav"];
    newImage = [newImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, newImage.size.width/2 - 10, 0, newImage.size.width/2 - 10)];
    [self.navigationBar setBackgroundImage:newImage forBarMetrics:UIBarMetricsDefault];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


+ (void)initialize {
    DEF_DEBUG(@"只运行一次");
}


/**
 *  通过拦截push方法来设置每个push进来的控制器的返回按钮   http://www.cnblogs.com/gchlcc/p/5469350.html
 */
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 如果push进来的不是第一个控制器
    if (self.childViewControllers.count > 0) {
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:@"titlebar_icon_goback" selectedImage:@"titlebar_icon_goback" addTarget:self action:@selector(backAction)];
        // 隐藏底部的工具条
        viewController.hidesBottomBarWhenPushed = YES;
    }
    // 一旦调用super的pushViewController方法,就会创建子控制器viewController的view并调用viewController的viewDidLoad方法。可以在viewDidLoad方法中重新设置自己想要的左上角按钮样式
    [super pushViewController:viewController animated:animated];
}

-(void)backAction{
    [self popViewControllerAnimated:YES];
}

@end






